import axios from 'axios'
import qs from 'qs'

const BASEURL = '/Home';
// export const baseUrl = 'http://m.aihera.cn';

const instance = axios.create({
  baseURL: BASEURL,
  timeout: 8000,
  headers: {
    'X-Requested-With': 'XMLHttpRequest',
    'Content-Type': 'application/x-www-form-urlencoded',
  },
});
var uid

// // 请求拦截器 发送请求之前做一些处理
instance.interceptors.request.use(function(config) {

  if (sessionStorage.uid) {
    if (config.url.indexOf('uid') > 0) {
      config.url = config.url + parseInt(sessionStorage.uid)
    }
  }
  //   if (sessionStorage.uid) {
  //   // 初始化openid
  //   if (config.url.indexOf('uid') > 0) {
  //     config.url = config.url
  //   } else if (config.url.indexOf('?') > 0) {
  //     config.url += '&openid=' + sessionStorage.openid
  //   } else {
  //     config.url += '?openid=' + sessionStorage.openid
  //   }
  // }
  // 数据的处理
  if (config.method === 'post' || config.method === 'put') {
    config.data = qs.stringify(config.data)
  }
  return config
}, function(error) {
  // 当请求异常时做一些处理
  return Promise.reject(error)
})

// 首页
export function home() {
  return instance({
    url: `/Index/index`,
    method: 'GET'
  })
}

// 发送验证码
export function sendcode(mobile) {
  return instance({
    url: `SendCode/sendCode`,
    method: 'POST',
    data: {
      'mobile': mobile,
    }
  })
}
//重置密码
export function forgetpwd(mobile, pwd, code) {
  return instance({
    url: `Public/resetpwd`,
    method: 'POST',
    data: {
      'account': mobile,
      'pwd': pwd,
      'code': code,
    }
  })
}

// 修改门店信息
export function editstore(phone, work_time, work_days) {
  return instance({
    url: `Index/setcontact`,
    method: 'POST',
    data: {
      'phone': phone,
      'work_time': work_time,
      'work_days': work_days
    }
  })
}
//搜索用户
export function searchuser(kw, p, num) {
  return instance({
    url: `Index/users?kw=` + kw + `&p=` + p + `&num=` + num,
    method: 'GET',
  })
}
//会员列表
export function personlist(kw, p, num) {
  return instance({
    url: `Index/member?kw=` + kw + `&p=` + p + `&num=` + num,
    method: 'GET',
  })
}
//详细资料
export function persondetails(uid) {
  return instance({
    url: `Index/member_detail?uid=` + uid,
    method: 'GET',
  })
}
//打卡办卡记录
export function cardlog(type, uid, p, num) {
  return instance({
    url: `Index/card_log?type=` + type + `&uid=` + uid + `&p=` + p + `&num=` + num,
    method: 'GET',
  })
}
//点评详情
export function storecomment(id) {
  return instance({
    url: `Index/review?id=` + id,
    method: 'GET',
  })
}
//孩子管理
export function childlist(uid, kw, p, num) {
  return instance({
    url: `Index/children?uid=` + uid + `&kw=` + kw + `&p=` + p + `&num=` + num,
    method: 'GET',
  })
}
//孩子管理
export function childinfo(id, uid) {
  return instance({
    url: `Index/childinfo?id=` + id + `&uid=` + uid,
    method: 'GET',
  })
}

//修改增加孩子信息
export function editchild(id, uid, truename, parent, age) {
  return instance({
    url: `Index/savechild`,
    method: 'POST',
    data: {
      id: id,
      uid: uid,
      truename: truename,
      parent: parent,
      age: age
    }
  })
}

//孩子打卡
export function clockoperation(id, uid) {
  return instance({
    url: `Index/signin?id=` + id + `&uid=` + uid,
    method: 'GET',
  })
}
//孩子执行打卡
export function doclockoperation(id, uid, num, teacher) {
  return instance({
    url: `Index/dosignin`,
    method: 'POST',
    data: {
      id: id,
      uid: uid,
      num: num,
      teacher: teacher
    }
  })
}
//孩子执行办卡
export function applycard(childid, uid, times) {
  return instance({
    url: `Index/banka`,
    method: 'POST',
    data: {
      id: childid,
      uid: uid,
      num: times
    }
  })
}

//讲师列表
export function teacherlist(p, num) {
  return instance({
    url: `Index/teacher?p=` + p + `&num=` + num,
    method: 'GET',
  })
}
//讲师详情
export function teacherdetail(id) {
  return instance({
    url: `Index/teacherdetail?id=` + id,
    method: 'GET',
  })
}
//讲师编辑
export function teacheredit(id, truename, mobile, pwd, status) {
  return instance({
    url: `Index/teacheredit`,
    method: 'POST',
    data: {
      id: id,
      truename: truename,
      mobile: mobile,
      pwd: pwd,
      status: status
    }
  })
}
//讲师点评
export function teacherreview(id, p, num) {
  return instance({
    url: `Index/teacherreview?teacher=` + id + `&p=` + p + `&num=` + num,
    method: 'GET',
  })
}


// 登录
export function login(jsonPost) {
  return instance({
    url: `Public/login`,
    method: 'POST',
    data: jsonPost,
  })
}
// 讲师首页
export function teacherIndex(jsonGet) {
  return instance({
    url: `Teacher/index/review/` + jsonGet.review,
    method: 'GET',
  })
}

// 讲师参数
export function teacherInfo() {
  return instance({
    url: `Teacher/info`,
    method: 'GET',
  })
}

// 学生参数
export function childInfo(jsonPost) {
  return instance({
    url: `Teacher/detail`,
    method: 'POST',
    data: jsonPost,
  })
}

// 老师点评
export function teacherComment(jsonPost) {
  return instance({
    url: `Teacher/review`,
    method: 'POST',
    data: jsonPost,
  })
}